/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerSearchCondition;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ 
/*     */ public class ChangeCustomerCategory extends AbstractAction
/*     */ {
/*     */   public ChangeCustomerCategory(AbstractHttpServlet servlet)
/*     */   {
/*  27 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  34 */     User loginUser = getLoginUser(request);
/*  35 */     String userId = loginUser.userId;
/*  36 */     response.setContentType("text/html;charset=utf-8");
/*  37 */     PrintWriter out = response.getWriter();
/*  38 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  40 */     int categoryId = Util.getURLIntParameter(request
/*  41 */       .getParameter("CategoryId"));
/*     */ 
/*  43 */     String types = Util.getURLParameter(request.getParameter("Types"));
/*  44 */     String customerIds = Util.getURLParameter(request
/*  45 */       .getParameter("CustomerIds"));
/*     */ 
/*  47 */     String selectAll = Util.getURLParameter(request
/*  48 */       .getParameter("selectAll"));
/*     */ 
/*  51 */     if ("1".equals(selectAll))
/*     */     {
/*  53 */       CustomerSearchCondition searchCondition = new CustomerSearchCondition(
/*  54 */         request, loginUser, false);
/*     */ 
/*  56 */       CustomerManager manager = new CustomerManager();
/*  57 */       int result = manager.changeAllCategoryId(categoryId, 
/*  58 */         searchCondition, loginUser);
/*  59 */       jsonObject.put("error", "0");
/*  60 */       jsonObject.put("updateNum", Integer.valueOf(result));
/*  61 */       out.println(jsonObject);
/*  62 */       out.flush();
/*  63 */       out.close();
/*  64 */       return;
/*     */     }
/*     */ 
/*  68 */     if ((customerIds == null) || (customerIds.trim().length() == 0) || 
/*  69 */       (types == null) || (types.trim().length() == 0)) {
/*  70 */       jsonObject.put("error", "1");
/*  71 */       out.println(jsonObject);
/*  72 */       out.flush();
/*  73 */       out.close();
/*  74 */       return;
/*     */     }
/*     */ 
/*  77 */     String[] customerType = types.split(",");
/*  78 */     String[] customerId = customerIds.split(",");
/*  79 */     if ((customerType == null) || (customerId == null) || 
/*  80 */       (customerType.length != customerId.length)) {
/*  81 */       jsonObject.put("error", "1");
/*  82 */       out.println(jsonObject);
/*  83 */       out.flush();
/*  84 */       out.close();
/*  85 */       return;
/*     */     }
/*  87 */     List updateCustomerIds = new ArrayList();
/*  88 */     CustomerManager manager = new CustomerManager();
/*  89 */     for (int i = 0; i < customerId.length; i++) {
/*  90 */       boolean isPerson = "1".equals(customerType[i]);
/*  91 */       if (!isPerson)
/*     */       {
/*     */         try
/*     */         {
/*  97 */           int result = manager.changeCategoryId(Util.str2Int(customerId[i]), 
/*  98 */             categoryId, userId);
/*  99 */           if (result >= 1)
/* 100 */             updateCustomerIds.add(customerId[i]);
/*     */         }
/*     */         catch (DBException e) {
/* 103 */           e.printStackTrace();
/*     */         } catch (SQLException e) {
/* 105 */           e.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/* 108 */     jsonObject.put("error", "0");
/* 109 */     jsonObject.put("updateIds", updateCustomerIds.toArray());
/* 110 */     out.println(jsonObject);
/* 111 */     out.flush();
/* 112 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ChangeCustomerCategory
 * JD-Core Version:    0.6.1
 */